/**
 * 类型定义统一导出
 * 提供所有类型的统一访问入口
 */

// 基础类型
export * from './base.types'

// 项目相关类型
export * from './project.types'

// 应用相关类型
export * from './app.types'

// 系统相关类型
export * from './system.types'

// 文件相关类型
export * from './file.types'

/**
 * 类型命名空间
 * 提供分组访问类型的方式
 */
export namespace Types {
  // 基础类型命名空间
  export namespace Base {
    export type {
      StandardResponse,
      ServiceResult,
      IPCError,
      PaginationParams,
      PaginatedResult,
      BaseFileInfo,
      OperationLog,
      ValidationRule,
      ValidationResult,
      BaseConfig,
      EventListener,
      UnsubscribeFunction,
      AsyncOperationState,
      CacheConfig,
      RetryConfig,
      BaseFilter,
      SortConfig,
      SearchConfig,
      BaseExportConfig,
      BaseImportConfig,
      Permission,
      SessionInfo,
      SystemStatus,
      Notification,
      ThemeConfig,
      LocaleConfig,
      AppSettings
    } from './base.types'
  }

  // 项目类型命名空间
  export namespace Project {
    export type {
      ProjectData,
      ProjectMetadata,
      CreateProjectRequest,
      UpdateProjectRequest,
      ProjectQueryParams,
      ProjectExportConfig,
      ProjectExportRequest,
      ProjectImportConfig,
      ProjectImportRequest,
      ProjectTemplate,
      ProjectStats,
      ProjectSettings,
      ProjectHistory,
      ProjectCollaboration,
      ProjectBackup,
      ProjectVersion,
      ProjectAnalytics,
      ProjectSearchResult,
      ProjectPermissions,
      ProjectStatus,
      ProjectSortOption,
      ProjectFilter,
      Resolution
    } from './project.types'
  }

  // 应用类型命名空间
  export namespace App {
    export type {
      AppInfo,
      AppState,
      WindowState,
      WindowConfig,
      MenuItemConfig,
      AppMenuConfig,
      DialogOptions,
      FileDialogOptions,
      SaveDialogOptions,
      NotificationOptions,
      UpdateInfo,
      UpdateCheckResult,
      DownloadProgress,
      AppPerformance,
      LogLevel,
      LogEntry,
      AppConfig,
      KeyboardShortcut,
      AppTheme,
      PluginInfo,
      ExtensionPoint,
      AppError
    } from './app.types'
  }

  // 系统类型命名空间
  export namespace System {
    export type {
      SystemInfo,
      CpuInfo,
      NetworkInterface,
      UserInfo,
      MemoryUsage,
      CpuUsage,
      DiskInfo,
      NetworkStats,
      ProcessInfo,
      SystemPerformance,
      SystemMonitorConfig,
      SystemPaths,
      EnvironmentVariables,
      SystemService,
      SystemEvent,
      PowerStatus,
      DisplayInfo,
      AudioDevice,
      SystemPermission,
      SystemSecurity,
      SystemBackup,
      SystemUpdate,
      SystemDiagnostics,
      SystemConfig
    } from './system.types'
  }

  // 文件类型命名空间
  export namespace File {
    export type {
      FileInfo,
      FilePermissions,
      DirectoryContent,
      FileOperationOptions,
      FileSearchOptions,
      FileSearchResult,
      FileWatchOptions,
      FileChangeEvent,
      AssetData,
      AssetType,
      AssetMetadata,
      AssetLicense,
      AssetImportOptions,
      AssetImportRequest,
      AssetExportOptions,
      AssetQueryParams,
      FileUploadProgress,
      FileDownloadProgress,
      FileCompressionOptions,
      FileExtractionOptions,
      FileSyncOptions,
      FileSyncResult,
      FileBackupConfig,
      FileVersion,
      FileShare,
      FileStats
    } from './file.types'
  }
}

/**
 * 常用类型别名
 */
export type IResponse<T = any> = Types.Base.StandardResponse<T>
export type IResult<T = any> = Types.Base.ServiceResult<T>
export type IProject = Types.Project.ProjectData
export type IProjectTemplate = Types.Project.ProjectTemplate
export type IAppInfo = Types.App.AppInfo
export type ISystemInfo = Types.System.SystemInfo
export type IFileInfo = Types.File.FileInfo
export type IAssetData = Types.File.AssetData

/**
 * 工具类型
 */
export type Nullable<T> = T | null
export type Optional<T> = T | undefined
export type DeepPartial<T> = {
  [P in keyof T]?: T[P] extends object ? DeepPartial<T[P]> : T[P]
}
export type DeepRequired<T> = {
  [P in keyof T]-?: T[P] extends object ? DeepRequired<T[P]> : T[P]
}
export type KeysOfType<T, U> = {
  [K in keyof T]: T[K] extends U ? K : never
}[keyof T]
export type ValuesOfType<T, U> = T[KeysOfType<T, U>]

/**
 * 事件类型
 */
export interface TypedEvent<T = any> {
  type: string
  data: T
  timestamp: string
  source?: string
}

/**
 * API响应包装器
 */
export interface ApiResponse<T = any> extends Types.Base.StandardResponse<T> {
  requestId?: string
  duration?: number
  cached?: boolean
}

/**
 * 错误详情
 */
export interface ErrorDetails {
  code: string | number
  message: string
  details?: any
  stack?: string
  timestamp: string
  context?: Record<string, any>
}

/**
 * 配置选项
 */
export interface ConfigOptions {
  [key: string]: any
}

/**
 * 回调函数类型
 */
export type Callback<T = any> = (error: Error | null, result?: T) => void
export type AsyncCallback<T = any> = (error: Error | null, result?: T) => Promise<void>

/**
 * 事件处理器类型
 */
export type EventHandler<T = any> = (event: TypedEvent<T>) => void | Promise<void>

/**
 * 中间件类型
 */
export type Middleware<T = any> = (
  context: T,
  next: () => Promise<void>
) => Promise<void>

/**
 * 验证器类型
 */
export type Validator<T = any> = (value: T) => boolean | string | Promise<boolean | string>

/**
 * 转换器类型
 */
export type Transformer<TInput, TOutput> = (input: TInput) => TOutput | Promise<TOutput>

/**
 * 过滤器类型
 */
export type Filter<T = any> = (item: T) => boolean

/**
 * 比较器类型
 */
export type Comparator<T = any> = (a: T, b: T) => number

/**
 * 映射器类型
 */
export type Mapper<TInput, TOutput> = (item: TInput, index?: number) => TOutput

/**
 * 归约器类型
 */
export type Reducer<T, TResult> = (accumulator: TResult, current: T, index?: number) => TResult

/**
 * 谓词类型
 */
export type Predicate<T = any> = (item: T) => boolean

/**
 * 选择器类型
 */
export type Selector<TState, TResult> = (state: TState) => TResult

/**
 * 动作类型
 */
export interface Action<TType = string, TPayload = any> {
  type: TType
  payload?: TPayload
  meta?: any
  error?: boolean
}

/**
 * 状态更新器类型
 */
export type StateUpdater<T> = (prevState: T) => T

/**
 * 依赖注入容器类型
 */
export interface DIContainer {
  register<T>(token: string | symbol, factory: () => T): void
  resolve<T>(token: string | symbol): T
  has(token: string | symbol): boolean
}

/**
 * 插件接口
 */
export interface Plugin {
  name: string
  version: string
  install(app: any, options?: any): void
  uninstall?(app: any): void
}

/**
 * 生命周期钩子
 */
export interface LifecycleHooks {
  beforeCreate?(): void | Promise<void>
  created?(): void | Promise<void>
  beforeMount?(): void | Promise<void>
  mounted?(): void | Promise<void>
  beforeUpdate?(): void | Promise<void>
  updated?(): void | Promise<void>
  beforeDestroy?(): void | Promise<void>
  destroyed?(): void | Promise<void>
}

/**
 * 默认导出所有类型
 */
export default Types
